<?php
require 'config/dataSource.php';
class File{
    private $name;
    private $mime;
    private $size;
    private $data;
    private $content;
    private $error;
    public function __construct($file) {
        if($file['error']==0){
            $this->name= mysql_real_escape_string($file['name']);
            $this->name= strip_tags($this->name);
            //$this->mime= mysql_real_escape_string($file['type']);
            //$this->mime= strip_tags($this->mime);
            $this->data= $file['tmp_name'];
            
            $this->size= intval($file['size']);
            $this->size= mysql_real_escape_string($this->size);
            $this->size= strip_tags($this->size);
            
            $this->mime = $file['type'];
            $this->mime=(get_magic_quotes_gpc()==0 ? mysql_real_escape_string(
            $file['type']) : mysql_real_escape_string(
            stripslashes ($file)));
            
            $fp      = fopen($this->data, 'r');
            $this->content = fread($fp, filesize($this->data));
            $this->content = addslashes($this->content);
            fclose($fp);
            
            
            $this->error=false;
        } else {
            $this->error=true;
        }
        
    }
    public function saveWithoutReply($userID,$forumID){
        $query = mysql_query("INSERT INTO file VALUES(DEFAULT,'{$this->name}','{$this->mime}','{$this->size}','{$this->content}',now(),now(),'{$userID}','{$forumID}',DEFAULT,'f')");
        if($query){
            
        }
    }
    public function saveWithReply($userID,$forumID,$replyID){
        $query = mysql_query("INSERT INTO file VALUES(DEFAULT,'{$this->name}','{$this->mime}','{$this->size}','{$this->content}',now(),now(),'{$userID}','{$forumID}','{$replyID}','f')");
        if($query){
            
        }
    }
   

    public function error(){
        return $this->error;
    }
            
}

?>